package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品控制器
 *
 * @author liudo
 * @version 1.0
 * @project sky-take-out
 * @date 2023/12/5 14:08:19
 */
@RestController
@RequestMapping("/admin/dish")
@RequiredArgsConstructor
public class DishController {

    private final DishService dishService;

    /**
     * 保存菜品
     *
     * @param dishDTO 碟形dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> save(@RequestBody DishDTO dishDTO) {
        dishService.save(dishDTO);
        return Result.success();
    }

    /**
     * 页
     *
     * @param dishPageQueryDTO 菜页查询dto
     * @return {@link Result}<{@link PageResult}<{@link DishVO}>>
     */
    @GetMapping("/page")
    public Result<PageResult<DishVO>> page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult<DishVO> pageResult = dishService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除批
     *
     * @param ids ids
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> removeBatch(@RequestParam List<String> ids) {
        dishService.removeBatch(ids);
        return Result.success();
    }

    /**
     * id信息
     *
     * @param id id
     * @return {@link Result}<{@link DishVO}>
     */
    @GetMapping("/{id}")
    public Result<DishVO> infoById(@PathVariable Long id) {
        DishVO dishVO = dishService.infoById(id);
        return Result.success(dishVO);
    }

    /**
     * 修改
     *
     * @param dishDTO 碟形dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> modify(@RequestBody DishDTO dishDTO) {
        dishService.modify(dishDTO);
        return Result.success();
    }


    /**
     * 按类别id列表
     *
     * @param categoryId 类别id
     * @return {@link Result}<{@link List}<{@link Dish}>>
     */
    @GetMapping("/list")
    public Result<List<Dish>> listByCategoryId(Long categoryId) {
        List<Dish> dishVOList = dishService.listByCategoryId(categoryId);
        return Result.success(dishVOList);
    }
}
